package com.weixin.controller;

import java.io.UnsupportedEncodingException;
import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.jfinal.core.Controller;
import com.weixin.dao.Province;

public class ProvinceController extends Controller{
	private Province dao = new Province();
	/**
	 * 查询所有的省份
	 */
	public void selectAll(){
		
		List<Province> provinces = dao.selectAll();
		JSONObject json = new JSONObject();
		if (provinces.size() == 0) {
			json.put("code", 0);
		}else {
			
			json.put("list", provinces);
		}
		
		
		renderJsp("/static/welcome1.jsp");
	}
	
	public void toselectAll(){
		String province_id = getPara("provinces");
		String city_id = getPara("city");
		String store_id = getPara("stores");
		
		
		String province_name = getPara("province_name");
		String city_name = getPara("city_name");
		String store_name = getPara("store_name");
		
		try {
			province_name   = new String( province_name.getBytes("ISO-8859-1") , "utf-8");
			city_name   = new String( city_name.getBytes("ISO-8859-1") , "utf-8");
			store_name   = new String( store_name.getBytes("ISO-8859-1") , "utf-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		setAttr("province_name", province_name);
		setAttr("city_name", city_name);
		setAttr("store_name", store_name);
		
		setAttr("province_id", province_id);
		setAttr("city_id", city_id);
		setAttr("store_id", store_id);
		
		renderJsp("/static/welcome1.jsp");
	}
}
